package com.ruoyi.web.controller.patent;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.TycPatentZd;
import com.ruoyi.service.ITycPatentZdService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专利类型Controller
 * 
 * @author ruoyi
 * @date 2020-09-11
 */
@Controller
@RequestMapping("/ruoyi/zd")
public class TycPatentZdController extends BaseController
{
    private String prefix = "ruoyi/zd";

    @Autowired
    private ITycPatentZdService tycPatentZdService;

    @RequiresPermissions("ruoyi:zd:view")
    @GetMapping()
    public String zd()
    {
        return prefix + "/zd";
    }

    /**
     * 查询专利类型列表
     */
    @RequiresPermissions("ruoyi:zd:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TycPatentZd tycPatentZd)
    {
        startPage();
        List<TycPatentZd> list = tycPatentZdService.selectTycPatentZdList(tycPatentZd);
        return getDataTable(list);
    }

    /**
     * 导出专利类型列表
     */
    @RequiresPermissions("ruoyi:zd:export")
    @Log(title = "专利类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TycPatentZd tycPatentZd)
    {
        List<TycPatentZd> list = tycPatentZdService.selectTycPatentZdList(tycPatentZd);
        ExcelUtil<TycPatentZd> util = new ExcelUtil<TycPatentZd>(TycPatentZd.class);
        return util.exportExcel(list, "zd");
    }

    /**
     * 新增专利类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存专利类型
     */
    @RequiresPermissions("ruoyi:zd:add")
    @Log(title = "专利类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TycPatentZd tycPatentZd)
    {

        return toAjax(tycPatentZdService.insertTycPatentZd(tycPatentZd));
    }

    /**
     * 修改专利类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TycPatentZd tycPatentZd = tycPatentZdService.selectTycPatentZdById(id);
        mmap.put("tycPatentZd", tycPatentZd);
        return prefix + "/edit";
    }

    /**
     * 修改保存专利类型
     */
    @RequiresPermissions("ruoyi:zd:edit")
    @Log(title = "专利类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TycPatentZd tycPatentZd)
    {
        return toAjax(tycPatentZdService.updateTycPatentZd(tycPatentZd));
    }

    /**
     * 删除专利类型
     */
    @RequiresPermissions("ruoyi:zd:remove")
    @Log(title = "专利类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tycPatentZdService.deleteTycPatentZdByIds(ids));
    }
}
